<template>
  <view class="payment-page">
    <!-- 课程信息卡片 -->
    <view class="course-card">
      <image class="course-image" src="@/static/video_preview/爬.png" />
      <view class="course-info">
        <!-- 商品名 -->
        <text class="course-title">{{ videoAbout.videoName }}</text>
        <!-- 商品备注 -->
        <text class="course-description">{{ videoAbout.videoRemake }}</text>
        <view class="price-section">
          <!-- 商品现价 -->
          <text class="new-price">¥ {{ videoAbout.price }}</text>
          <!-- 商品原价 -->
          <text class="old-price">¥ {{ videoAbout.oldPrice }}</text>
        </view>
      </view>
    </view>

    <!-- 当前支付价格 -->
    <view class="payment-info">
      <view class="payment-info-text">
        <text class="payment-title">现在支付</text>
        <text class="payment-amount">¥ {{ videoAbout.price }}</text>
      </view>
      <text class="price-details">价格详情</text>
    </view>

    <!-- 支付方式选择 -->
    <view class="payment-methods">
      <view class="payment-method" @click="selectPayment('alipay')">
        <image class="payment-icon" src="@/static/video_preview/支付宝.png" />
        <text class="payment-text">支付宝</text>
        <view :class="['radio', { selected: selectedPayment === 'alipay' }]"></view>
      </view>
      <view class="payment-method" @click="selectPayment('wechat')">
        <image class="payment-icon" src="@/static/video_preview/微信.png" />
        <text class="payment-text">微信支付</text>
        <view :class="['radio', { selected: selectedPayment === 'wechat' }]"></view>
      </view>
      <view class="payment-method" @click="selectPayment('wallet')">
        <image class="payment-icon" src="@/static/video_preview/钱包.png" />
        <text class="payment-text">钱包支付</text>
        <view :class="['radio', { selected: selectedPayment === 'wallet' }]"></view>
      </view>
      <view class="other-methods">
        <text class="other-methods-text">其他支付方式</text>
      </view>
    </view>

    <!-- 底部确认信息 -->
    <view class="agreement">
      <text>
        我同意 <text class="link">购买守则</text>、
        <text class="link">取消政策</text> 和
        <text class="link">退款政策</text>。我也同意支付以下所示总金额（含服务费）。
      </text>
    </view>

    <!-- 确认订单按钮 -->
    <button class="confirm-button" @click="confirmOrder">
      确认订单 · ¥ {{ videoAbout.price }}
    </button>
  </view>
</template>

<script>
import { mapState } from 'vuex';

export default {
  computed: {
    ...mapState({
      videoAbout: state => JSON.parse(JSON.stringify(state.videoAbout)),
      userInfo: state => JSON.parse(JSON.stringify(state.userInfo)) // 获取用户信息
    })
  },
  data() {
    return {
      selectedPayment: 'alipay' // 默认选择支付宝
    };
  },
  methods: {
    selectPayment(method) {
      this.selectedPayment = method;
    },
    // 确认订单并跳转到订单成功页面
    confirmOrder() {
      // 如果选择了钱包支付，判断余额是否足够
      if (this.selectedPayment === 'wallet') {
        if (this.userInfo.userMoney < this.videoAbout.price) {
          uni.showToast({
            title: '余额不足，请充值',
            icon: 'none'
          });
          return;
        }
		this.videoAbout.videoName
		userInfo
		
		
      }

      // 用户余额足够或选择其他支付方式，确认订单并跳转到订单成功页面
      uni.navigateTo({
        url: '/pages/order_successful/index'
      });
    }
  }
};
</script>

<style scoped>
.payment-page {
  display: flex;
  flex-direction: column;
  min-height: 95vh;
  padding: 10px;
  font-family: Arial, sans-serif;
  background-color: #f8f8f8;
}

/* 样式省略，和之前保持一致 */
.payment-page {
  display: flex;
  flex-direction: column;
  min-height: 95vh;
  padding: 10px;
  font-family: Arial, sans-serif;
  background-color: #f8f8f8;
}

.course-card,
.payment-info,
.payment-methods,
.agreement {
  margin-bottom: 15px;
}

.course-card {
  display: flex;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 10px;
  background-color: #fff;
}

.course-image {
  width: 80px;
  height: 80px;
  border-radius: 4px;
  margin-right: 10px;
}

.course-info {
  flex: 1;
}

.course-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 5px;
}

.course-description {
  font-size: 12px;
  color: #666;
  margin-bottom: 5px;
}

.price-section {
  display: flex;
  align-items: center;
}

.new-price {
  font-size: 16px;
  color: #e60012;
  font-weight: bold;
  margin-right: 8px;
}

.old-price {
  font-size: 14px;
  color: #999;
  text-decoration: line-through;
}

.payment-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background-color: #fff;
}

.payment-info-text {
  display: flex;
  align-items: center;
}

.payment-title {
  font-size: 14px;
  color: #333;
  margin-right: 5px;
}

.payment-amount {
  font-size: 16px;
  color: #e60012;
  font-weight: bold;
}

.price-details {
  font-size: 12px;
  color: #007aff;
  text-decoration: underline;
}

.payment-methods {
  border: 1px solid #ddd;
  border-radius: 8px;
  background-color: #fff;
}

.payment-method {
  display: flex;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #ddd;
  cursor: pointer;
}

.payment-method:last-child {
  border-bottom: none;
}

.payment-icon {
  width: 24px;
  height: 24px;
  margin-right: 10px;
}

.payment-text {
  font-size: 14px;
  color: #333;
  flex: 1; /* 占据剩余空间，使单选框对齐到右侧 */
}

/* 自定义单选框样式 */
.radio {
  width: 16px;
  height: 16px;
  border: 2px solid #ccc;
  border-radius: 50%;
  margin-left: auto; /* 将单选框推到右侧 */
}

.radio.selected {
  background-color: #007aff; /* 选中状态下的颜色 */
  border-color: #007aff;
}

.other-methods {
  padding: 10px;
}

.other-methods-text {
  font-size: 14px;
  color: #333;
}

.agreement {
  font-size: 12px;
  color: #666;
}

.link {
  color: #007aff;
  text-decoration: underline;
}

.confirm-button {
  margin-top: auto;
  width: 100%;
  height: 45px;
  background-color: #ff4500;
  color: white;
  font-size: 16px;
  font-weight: bold;
  text-align: center;
  line-height: 45px;
  border-radius: 24px;
  border: none;
}
</style>
